/*
 * Copyright (c) 2018. 玺得（深圳）科技有限公司.保留所有权利. http://www.pi-top.com/ 玺得（深圳）科技有限公司保留所有代码著作权.如有任何疑问请访问官方网站与我们联系. 代码只针对特定需求定制编码，不得在未经允许或授权的情况下对外传播扩散.恶意传播者，法律后果自行承担. 本代码仅用于pps-cloud系统.
 */
package com.pitop.repair.ctrl;

import com.alibaba.fastjson.JSON;
import com.pitop.core.entity.BeanRet;
import com.pitop.core.entity.Page;
import com.pitop.core.tools.redis.RedisUtils;
import com.pitop.repair.entity.RepairFeedback;
import com.pitop.repair.service.RepairFeedbackSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

/**
 * 维修反馈 控制器
 *
 * @author pi-top
 */
@RestController
@RequestMapping("/repairFeedback")
@Slf4j
@Api(value = "维修反馈控制器", description = "维修反馈控制器")
public class RepairFeedbackCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private RepairFeedbackSV repairFeedbackSV;

    /**
     * 查询RepairFeedback一个详情信息
     *
     * @param id   id
     * @param code 维修反馈编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询RepairFeedback一个详情信息", notes = "查询RepairFeedback一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "维修反馈编码", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public RepairFeedback load(java.lang.Long id, java.lang.String code) {
        if (id == null) {
            return null;
        }
        if (code == null) {
            return null;
        }
        RepairFeedback repairFeedback = repairFeedbackSV.load(id, code);
        log.info(JSON.toJSONString(repairFeedback));
        return repairFeedback;
    }


    /**
     * 根据条件id查询RepairFeedback一个详情信息
     *
     * @param id id
     * @return BeanRet
     */
    @ApiOperation(value = "查询RepairFeedback一个详情信息", notes = "查询RepairFeedback一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public RepairFeedback loadById(@PathVariable java.lang.Long id) {
        if (id == null) {
            return null;
        }
        RepairFeedback repairFeedback = repairFeedbackSV.loadById(id);
        log.info(JSON.toJSONString(repairFeedback));
        return repairFeedback;
    }

    /**
     * 根据条件code查询RepairFeedback一个详情信息
     *
     * @param code 维修反馈编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询RepairFeedback一个详情信息", notes = "查询RepairFeedback一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "维修反馈编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/code/{code}")
    @ResponseBody
    public RepairFeedback loadByCode(@PathVariable java.lang.String code) {
        if (code == null) {
            return null;
        }
        RepairFeedback repairFeedback = repairFeedbackSV.loadByCode(code);
        log.info(JSON.toJSONString(repairFeedback));
        return repairFeedback;
    }


    /**
     * 查询RepairFeedback信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询RepairFeedback信息集合", notes = "查询RepairFeedback信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "id", paramType = "query"),
            @ApiImplicitParam(name = "factoryCode", value = "工厂编码", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "维修反馈编码", paramType = "query"),
            @ApiImplicitParam(name = "testUnitCode", value = "测试硬件单元编码", paramType = "query"),
            @ApiImplicitParam(name = "staffCode", value = "员工编码", paramType = "query"),
            @ApiImplicitParam(name = "errorCode", value = "错误类型编码", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态：修复repaired，损坏broken", paramType = "query"),
            @ApiImplicitParam(name = "feedback", value = "反馈信息", paramType = "query"),
            @ApiImplicitParam(name = "createTimeBegin", value = "创建时间", paramType = "query"),
            @ApiImplicitParam(name = "createTimeEnd", value = "创建时间", paramType = "query"),
            @ApiImplicitParam(name = "sortColumns", value = "排序： createTime DESC， createTime ASC", paramType = "query"),
    })
    @PostMapping(value = "/list")
    @ResponseBody
    public List<RepairFeedback> list(@RequestBody @ApiIgnore RepairFeedback repairFeedback, Integer curPage, Integer pageSize) {
        Page<RepairFeedback> page = new Page<>(pageSize, curPage);
        List<RepairFeedback> repairFeedbacks = repairFeedbackSV.list(repairFeedback, page.genRowStart(), page.getPageSize());
        int total = repairFeedbackSV.count(repairFeedback);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return repairFeedbacks;
    }


    /**
     * 查询RepairFeedback信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询RepairFeedback信息集合", notes = "查询RepairFeedback信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "id", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "维修反馈编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public List<RepairFeedback> listByPk(java.lang.Long id, java.lang.String code, Integer curPage, Integer pageSize) {
        Page<RepairFeedback> page = new Page<>(pageSize, curPage);
        List<RepairFeedback> repairFeedbacks = repairFeedbackSV.list(id, code, page.genRowStart(), page.getPageSize());
        int total = repairFeedbackSV.count(id, code);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return repairFeedbacks;
    }

    /**
     * 统计RepairFeedback信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计RepairFeedback信息数量根据主键", notes = " 统计RepairFeedback信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "维修反馈编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(java.lang.Long id, java.lang.String code) {
        return repairFeedbackSV.count(id, code);
    }

    /**
     * 统计RepairFeedback信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计RepairFeedback信息数量", notes = "统计RepairFeedback信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", paramType = "query"),
            @ApiImplicitParam(name = "factoryCode", value = "工厂编码", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "维修反馈编码", paramType = "query"),
            @ApiImplicitParam(name = "testUnitCode", value = "测试硬件单元编码", paramType = "query"),
            @ApiImplicitParam(name = "staffCode", value = "员工编码", paramType = "query"),
            @ApiImplicitParam(name = "errorCode", value = "错误类型编码", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态：修复repaired，损坏broken", paramType = "query"),
            @ApiImplicitParam(name = "feedback", value = "反馈信息", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query")
    })
    @PostMapping(value = "/count")
    @ResponseBody
    public Integer count(@RequestBody RepairFeedback repairFeedback) {
        return repairFeedbackSV.count(repairFeedback);
    }


    /**
     * 创建RepairFeedback
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建RepairFeedback", notes = "创建RepairFeedback")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "factoryCode", value = "工厂编码", paramType = "query"),
            @ApiImplicitParam(name = "testUnitCode", value = "测试硬件单元编码", paramType = "query"),
            @ApiImplicitParam(name = "staffCode", value = "员工编码", paramType = "query"),
            @ApiImplicitParam(name = "errorCode", value = "错误类型编码", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态：修复repaired，损坏broken", paramType = "query"),
            @ApiImplicitParam(name = "feedback", value = "反馈信息", paramType = "query"),
    })
    @PostMapping("/build")
    @ResponseBody
    public RepairFeedback build(@RequestBody @ApiIgnore RepairFeedback repairFeedback) {
        repairFeedbackSV.save(repairFeedback);
        return repairFeedback;
    }


    /**
     * 修改RepairFeedback
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改RepairFeedback", notes = "修改RepairFeedback")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", paramType = "query"),
            @ApiImplicitParam(name = "factoryCode", value = "工厂编码", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "维修反馈编码", paramType = "query"),
            @ApiImplicitParam(name = "testUnitCode", value = "测试硬件单元编码", paramType = "query"),
            @ApiImplicitParam(name = "staffCode", value = "员工编码", paramType = "query"),
            @ApiImplicitParam(name = "errorCode", value = "错误类型编码", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态：修复repaired，损坏broken", paramType = "query"),
            @ApiImplicitParam(name = "feedback", value = "反馈信息", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public RepairFeedback modify(@RequestBody @ApiIgnore RepairFeedback repairFeedback) {
        repairFeedbackSV.modify(repairFeedback);
        return repairFeedback;
    }

    /**
     * 删除RepairFeedback
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除RepairFeedback", notes = "删除RepairFeedback")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "维修反馈编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(java.lang.Long id, java.lang.String code) {
        repairFeedbackSV.delete(id, code);
        return BeanRet.create(true, "删除RepairFeedback成功");
    }

}
